package com.yaolisheng;

import com.tencentcloudapi.common.Credential;
import com.tencentcloudapi.common.exception.TencentCloudSDKException;
import com.tencentcloudapi.common.profile.ClientProfile;
import com.tencentcloudapi.common.profile.HttpProfile;
import com.tencentcloudapi.monitor.v20180724.MonitorClient;
import com.tencentcloudapi.monitor.v20180724.models.Dimension;
import com.tencentcloudapi.monitor.v20180724.models.GetMonitorDataRequest;
import com.tencentcloudapi.monitor.v20180724.models.GetMonitorDataResponse;
import com.tencentcloudapi.monitor.v20180724.models.Instance;
import com.tencentcloudapi.redis.v20180412.RedisClient;

/**
 * @author : yaols
 * Desc: 获取监控数据
 * Company: 神州数码信息系统有限公司
 * Date: ${YEAR}/${MONTH}/${DAY}/${TIME}
 */
public class GetMonitorDataAPI {
    private static final String secreId = "AKIDXu0td9TYR6XllX6QZVGsGQL4dz70f6JL";
    private static final String secreKey = "3tWv51jCSWN2UlpfIl15wa3JMFvSmxxk";

    public static void main(String[] args) {
        try {
            // 实例化一个认证对象，入参需要传入腾讯云账户secretId，secretKey,此处还需注意密钥对的保密
            // 密钥可前往https://console.cloud.tencent.com/cam/capi网站进行获取
            Credential cred = new Credential(secreId, secreKey);
            // 实例化一个http选项，可选的，没有特殊需求可以跳过
            HttpProfile httpProfile = new HttpProfile();
            httpProfile.setEndpoint("monitor.tencentcloudapi.com");
            // 实例化一个client选项，可选的，没有特殊需求可以跳过
            ClientProfile clientProfile = new ClientProfile();
            clientProfile.setHttpProfile(httpProfile);
            // 实例化要请求产品的client对象,clientProfile是可选的
            MonitorClient client = new MonitorClient(cred, "ap-shanghai", clientProfile);


            RedisClient redisClient = new RedisClient(cred, "ap-shanghai", clientProfile);


            // 实例化一个请求对象,每个接口都会对应一个request对象
            GetMonitorDataRequest req = new GetMonitorDataRequest();
            //命名空间--->>>包含数据是云服务器、云数据库、消息中间键等标识
            req.setNamespace("QCE/CVM");
            //指标名称---->>>>包含信息是cpu、内存、磁盘等标识
            req.setMetricName("Cpuloadavg5m");

            //req.setPeriod();
            //req.setStartTime();
            //req.setEndTime();


            Instance[] instances1 = new Instance[1];
            Instance instance1 = new Instance();

            Dimension[] dimensions1 = new Dimension[1];
            Dimension dimension1 = new Dimension();
            dimension1.setName("InstanceId");
            dimension1.setValue("ins-daa4lw9b");
            dimensions1[0] = dimension1;

            instance1.setDimensions(dimensions1);

            instances1[0] = instance1;

            req.setInstances(instances1);

            // 返回的resp是一个GetMonitorDataResponse的实例，与请求对象对应
            GetMonitorDataResponse resp = client.GetMonitorData(req);
            // 输出json格式的字符串回包
            System.out.println(GetMonitorDataResponse.toJsonString(resp));
        } catch (TencentCloudSDKException e) {
            System.out.println(e.toString());
        }
    }
}
